package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.subject.OneSubject;
import com.atguigu.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author kaixuan
 * @since 2020-05-29
 */
@Api(description = "课程分类管理")
@RestController
@RequestMapping("/eduservice/subject")
//@CrossOrigin //前后端分离解决跨域访问
public class EduSubjectController {

    @Autowired
    private EduSubjectService eduSubjectService;

    /**
     * 获取上传的Excel文件使用EasyExcel读取
     * @param file
     * @return eduSubjectService 通过有参构造 可以让没有交给spring管理的类调用service
     */
    @PostMapping("addSubject")
    public R addSubject(MultipartFile file){
        eduSubjectService.saveSubject(file, eduSubjectService);
        return R.ok();
    }


    @ApiOperation(value = "嵌套数据列表")
    @GetMapping("nestedList")
    public R nestedList(){
        List<OneSubject> nodeList = eduSubjectService.nestedList();
        return R.ok().data("items",nodeList);
    }

}

